CREATE
DATABASE if not exists `csc-pay`;
use
`csc-pay`;
-- ----------------------------
-- Table structure for pay_app
-- ----------------------------
DROP TABLE IF EXISTS `pay_app`;
CREATE TABLE `pay_app`
(
    `id`                bigint(19) NOT NULL AUTO_INCREMENT COMMENT '应用编号',
    `name`              varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci   NOT NULL COMMENT '应用名',
    `status`            tinyint                                                        NOT NULL COMMENT '开启状态',
    `remark`            varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '备注',
    `pay_notify_url`    varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '支付结果的回调地址',
    `refund_notify_url` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '退款结果的回调地址',
    `merchant_id`       bigint                                                         NOT NULL COMMENT '商户编号',
    `creator`           varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
    `create_time`       datetime                                                       NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`           varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
    `update_time`       datetime                                                       NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`           bit(1)                                                         NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`         bigint                                                         NOT NULL DEFAULT 1 COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 7
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT = '支付应用信息';

-- ----------------------------
-- Records of pay_app
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for pay_channel
-- ----------------------------
DROP TABLE IF EXISTS `pay_channel`;
CREATE TABLE `pay_channel`
(
    `id`          bigint(19) NOT NULL AUTO_INCREMENT COMMENT '商户编号',
    `code`        varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci   NOT NULL COMMENT '渠道编码',
    `status`      tinyint                                                        NOT NULL COMMENT '开启状态',
    `remark`      varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '备注',
    `fee_rate`    double                                                         NOT NULL DEFAULT 0 COMMENT '渠道费率，单位：百分比',
    `merchant_id` bigint(19) NOT NULL COMMENT '商户编号',
    `app_id`      bigint(19) NOT NULL COMMENT '应用编号',
    `config`      varchar(4096) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '支付渠道配置',
    `creator`     varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
    `create_time` datetime                                                       NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`     varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
    `update_time` datetime                                                       NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`     bit(1)                                                         NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`   bigint(19) NOT NULL DEFAULT 1 COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 18
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT = '支付渠道\n';

-- ----------------------------
-- Records of pay_channel
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for pay_merchant
-- ----------------------------
DROP TABLE IF EXISTS `pay_merchant`;
CREATE TABLE `pay_merchant`
(
    `id`          bigint(19) NOT NULL AUTO_INCREMENT COMMENT '商户编号',
    `no`          varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商户号',
    `name`        varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商户全称',
    `short_name`  varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商户简称',
    `status`      tinyint                                                      NOT NULL COMMENT '开启状态',
    `remark`      varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '备注',
    `creator`     varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
    `create_time` datetime                                                     NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`     varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
    `update_time` datetime                                                     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`     bit(1)                                                       NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`   bigint(19) NOT NULL DEFAULT 1 COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 6
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT = '支付商户信息';

-- ----------------------------
-- Records of pay_merchant
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for pay_notify_log
-- ----------------------------
DROP TABLE IF EXISTS `pay_notify_log`;
CREATE TABLE `pay_notify_log`
(
    `id`           bigint(19) NOT NULL AUTO_INCREMENT COMMENT '日志编号',
    `task_id`      bigint(19) NOT NULL COMMENT '通知任务编号',
    `notify_times` tinyint                                                        NOT NULL COMMENT '第几次被通知',
    `response`     varchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '请求参数',
    `status`       tinyint                                                        NOT NULL COMMENT '通知状态',
    `creator`      varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
    `create_time`  datetime                                                       NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`      varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
    `update_time`  datetime                                                       NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`      bit(1)                                                         NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`    bigint(19) NOT NULL DEFAULT 1 COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 363051
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT = '支付通知 App 的日志';

-- ----------------------------
-- Records of pay_notify_log
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for pay_notify_task
-- ----------------------------
DROP TABLE IF EXISTS `pay_notify_task`;
CREATE TABLE `pay_notify_task`
(
    `id`                bigint(19) NOT NULL AUTO_INCREMENT COMMENT '任务编号',
    `merchant_id`       bigint(19) NOT NULL COMMENT '商户编号',
    `app_id`            bigint(19) NOT NULL COMMENT '应用编号',
    `type`              tinyint                                                        NOT NULL COMMENT '通知类型',
    `data_id`           bigint(19) NOT NULL COMMENT '数据编号',
    `status`            tinyint                                                        NOT NULL COMMENT '通知状态',
    `merchant_order_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci   NOT NULL COMMENT '商户订单编号',
    `next_notify_time`  datetime                                                       NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '下一次通知时间',
    `last_execute_time` datetime                                                       NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次执行时间',
    `notify_times`      tinyint                                                        NOT NULL COMMENT '当前通知次数',
    `max_notify_times`  tinyint                                                        NOT NULL COMMENT '最大可通知次数',
    `notify_url`        varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '异步通知地址',
    `creator`           varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
    `create_time`       datetime                                                       NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`           varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
    `update_time`       datetime                                                       NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`           bit(1)                                                         NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`         bigint(19) NOT NULL DEFAULT 1 COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 112
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT = '商户支付、退款等的通知\n';

-- ----------------------------
-- Records of pay_notify_task
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for pay_order
-- ----------------------------
DROP TABLE IF EXISTS `pay_order`;
CREATE TABLE `pay_order`
(
    `id`                   bigint(19) NOT NULL AUTO_INCREMENT COMMENT '支付订单编号',
    `merchant_id`          bigint(19) NOT NULL COMMENT '商户编号',
    `app_id`               bigint(19) NOT NULL COMMENT '应用编号',
    `channel_id`           bigint(19) NULL DEFAULT NULL COMMENT '渠道编号',
    `channel_code`         varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '渠道编码',
    `merchant_order_id`    varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci   NOT NULL COMMENT '商户订单编号',
    `subject`              varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci   NOT NULL COMMENT '商品标题',
    `body`                 varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  NOT NULL COMMENT '商品描述',
    `notify_url`           varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '异步通知地址',
    `notify_status`        tinyint                                                        NOT NULL COMMENT '通知商户支付结果的回调状态',
    `amount`               bigint                                                         NOT NULL COMMENT '支付金额，单位：分',
    `channel_fee_rate`     double NULL DEFAULT 0 COMMENT '渠道手续费，单位：百分比',
    `channel_fee_amount`   bigint NULL DEFAULT 0 COMMENT '渠道手续金额，单位：分',
    `status`               tinyint                                                        NOT NULL COMMENT '支付状态',
    `user_ip`              varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci   NOT NULL COMMENT '用户 IP',
    `expire_time`          datetime                                                       NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '订单失效时间',
    `success_time`         datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '订单支付成功时间',
    `notify_time`          datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '订单支付通知时间',
    `success_extension_id` bigint(19) NULL DEFAULT NULL COMMENT '支付成功的订单拓展单编号',
    `refund_status`        tinyint                                                        NOT NULL COMMENT '退款状态',
    `refund_times`         tinyint                                                        NOT NULL COMMENT '退款次数',
    `refund_amount`        bigint                                                         NOT NULL COMMENT '退款总金额，单位：分',
    `channel_user_id`      varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '渠道用户编号',
    `channel_order_no`     varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '渠道订单号',
    `creator`              varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
    `create_time`          datetime                                                       NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`              varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
    `update_time`          datetime                                                       NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`              bit(1)                                                         NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`            bigint(19) NOT NULL DEFAULT 1 COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 125
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT = '支付订单\n';

-- ----------------------------
-- Records of pay_order
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for pay_order_extension
-- ----------------------------
DROP TABLE IF EXISTS `pay_order_extension`;
CREATE TABLE `pay_order_extension`
(
    `id`                  bigint(19) NOT NULL AUTO_INCREMENT COMMENT '支付订单编号',
    `no`                  varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '支付订单号',
    `order_id`            bigint(19) NOT NULL COMMENT '支付订单编号',
    `channel_id`          bigint(19) NOT NULL COMMENT '渠道编号',
    `channel_code`        varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '渠道编码',
    `user_ip`             varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '用户 IP',
    `status`              tinyint                                                      NOT NULL COMMENT '支付状态',
    `channel_extras`      varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '支付渠道的额外参数',
    `channel_notify_data` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '支付渠道异步通知的内容',
    `creator`             varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
    `create_time`         datetime                                                     NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`             varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
    `update_time`         datetime                                                     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`             bit(1)                                                       NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`           bigint(19) NOT NULL DEFAULT 1 COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 124
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT = '支付订单\n';

-- ----------------------------
-- Records of pay_order_extension
-- ----------------------------
BEGIN;
COMMIT;

-- ----------------------------
-- Table structure for pay_refund
-- ----------------------------
DROP TABLE IF EXISTS `pay_refund`;
CREATE TABLE `pay_refund`
(
    `id`                 bigint(19) NOT NULL AUTO_INCREMENT COMMENT '支付退款编号',
    `merchant_id`        bigint(19) NOT NULL COMMENT '商户编号',
    `app_id`             bigint(19) NOT NULL COMMENT '应用编号',
    `channel_id`         bigint(19) NOT NULL COMMENT '渠道编号',
    `channel_code`       varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci   NOT NULL COMMENT '渠道编码',
    `order_id`           bigint(19) NOT NULL COMMENT '支付订单编号 pay_order 表id',
    `trade_no`           varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci   NOT NULL COMMENT '交易订单号 pay_extension 表no 字段',
    `merchant_order_id`  varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci   NOT NULL COMMENT '商户订单编号（商户系统生成）',
    `merchant_refund_no` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci   NOT NULL COMMENT '商户退款订单号（商户系统生成）',
    `notify_url`         varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '异步通知商户地址',
    `notify_status`      tinyint                                                        NOT NULL COMMENT '通知商户退款结果的回调状态',
    `status`             tinyint                                                        NOT NULL COMMENT '退款状态',
    `type`               tinyint                                                        NOT NULL COMMENT '退款类型(部分退款，全部退款)',
    `pay_amount`         bigint                                                         NOT NULL COMMENT '支付金额,单位分',
    `refund_amount`      bigint                                                         NOT NULL COMMENT '退款金额,单位分',
    `reason`             varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci  NOT NULL COMMENT '退款原因',
    `user_ip`            varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '用户 IP',
    `channel_order_no`   varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci   NOT NULL COMMENT '渠道订单号，pay_order 中的channel_order_no 对应',
    `channel_refund_no`  varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '渠道退款单号，渠道返回',
    `channel_error_code` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '渠道调用报错时，错误码',
    `channel_error_msg`  varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '渠道调用报错时，错误信息',
    `channel_extras`     varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '支付渠道的额外参数',
    `expire_time`        datetime NULL DEFAULT NULL COMMENT '退款失效时间',
    `success_time`       datetime NULL DEFAULT NULL COMMENT '退款成功时间',
    `notify_time`        datetime NULL DEFAULT NULL COMMENT '退款通知时间',
    `creator`            varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
    `create_time`        datetime                                                       NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`            varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
    `update_time`        datetime                                                       NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`            bit(1)                                                         NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`          bigint(19) NOT NULL DEFAULT 1 COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 1
  CHARACTER SET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT = '退款订单';

-- ----------------------------
-- Records of pay_refund
-- ----------------------------
BEGIN;
COMMIT;

/*Table structure for table `pay_notify_refund_log` */

DROP TABLE IF EXISTS `pay_notify_refund_log`;

CREATE TABLE `pay_notify_refund_log`
(
    `id`           bigint(19) NOT NULL AUTO_INCREMENT COMMENT '日志编号',
    `order_id`     bigint(19) DEFAULT NULL COMMENT '订单号主键',
    `notify_times` tinyint(4) NOT NULL COMMENT '第几次被通知',
    `response`     varchar(2048) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '请求参数',
    `notify_url`   varchar(255) COLLATE utf8mb4_unicode_ci           DEFAULT NULL COMMENT '通知地址',
    `status`       tinyint(4) NOT NULL COMMENT '通知状态',
    `creator`      varchar(64) COLLATE utf8mb4_unicode_ci            DEFAULT '' COMMENT '创建者',
    `create_time`  datetime                                 NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`      varchar(64) COLLATE utf8mb4_unicode_ci            DEFAULT '' COMMENT '更新者',
    `update_time`  datetime                                 NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`      bit(1)                                   NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`    bigint(19) NOT NULL DEFAULT '0' COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 6
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_unicode_ci COMMENT ='支付回调本地通知 App 的日志';

-- -----------------------------------------
-- --------------见证宝相关start--------------
-- -----------------------------------------

-- ----------------------------
-- Table structure for pay_bank
-- ----------------------------
/*Table structure for table `pay_bank` */

DROP TABLE IF EXISTS `pay_bank`;

CREATE TABLE `pay_bank`
(
    `id`               bigint(19) NOT NULL AUTO_INCREMENT COMMENT '维一标识',
    `merchant_id`      bigint(19) NOT NULL COMMENT '商户编号',
    `card_no`          varchar(22)                                                  DEFAULT '' COMMENT '银行卡号',
    `phone`            varchar(11)                                                  DEFAULT '' COMMENT '银行卡的预留手机号',
    `bank_code`        varchar(50)                                                  DEFAULT '' COMMENT '银行代码:暂时组合，自定义+平安银行给定的code(有相同的)',
    `card_object`      tinyint(1) DEFAULT '1' COMMENT '卡对象:1个人,2企业(对公)',
    `card_type`        tinyint(1) DEFAULT '1' COMMENT '卡类型:1借记卡(储蓄卡),2信用卡',
    `card_code`        varchar(22)                                                  DEFAULT '' COMMENT '信用卡背面3个数字',
    `card_year`        varchar(4)                                                   DEFAULT '' COMMENT '信用卡有效年份',
    `card_month`       varchar(2)                                                   DEFAULT '' COMMENT '信用卡有效月份',
    `bank_name`        varchar(60)                                                  DEFAULT '' COMMENT '开户行支行名称 如:“中国工商银行股份有限公司北京樱桃园支行”',
    `union_bank`       varchar(15)                                                  DEFAULT '' COMMENT '支付行号，12 位数字',
    `union_bank_type`  int(2) DEFAULT '0' COMMENT '支付行号类型，0:空,1联行号,2:超级网银号',
    `parent_bank_name` varchar(50)                                                  DEFAULT '' COMMENT '开户银行名称',
    `bank_city_no`     varchar(50)                                                  DEFAULT '' COMMENT '开户行地区代码',
    `province`         varchar(50)                                                  DEFAULT '' COMMENT '开户行所在省',
    `city`             varchar(50)                                                  DEFAULT '' COMMENT '开户行所在市',
    `creator`          varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
    `create_time`      datetime NOT NULL                                            DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`          varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者',
    `update_time`      datetime NOT NULL                                            DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`          bit(1)   NOT NULL                                            DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`        bigint(19) NOT NULL DEFAULT '0' COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE,
    KEY                `merchant_id` (`merchant_id`) USING BTREE,
    KEY                `card_no` (`card_no`) USING BTREE
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8
  ROW_FORMAT = COMPACT COMMENT ='资金账户绑定的银行卡';

/*Data for the table `pay_bank` */

/*Table structure for table `pay_card` */

DROP TABLE IF EXISTS `pay_card`;

CREATE TABLE `pay_card`
(
    `id`               bigint(19) NOT NULL AUTO_INCREMENT COMMENT '维一标识',
    `merchant_id`      bigint(19) NOT NULL COMMENT '商户编号',
    `card_type`        int(1) DEFAULT '0' COMMENT '认证类型 ,0个人认证，1公司认证',
    `real_name`        varchar(20)                                                  DEFAULT '' COMMENT '身份证姓名(银行开户名称)，公司名称(银行开户名称)',
    `id_card`          varchar(20)                                                  DEFAULT '' COMMENT '身份证号或组织机构代码证',
    `phone`            varchar(11)                                                  DEFAULT '' COMMENT '手机号码,初始值为绑定第一张银行卡的预留手机号,后续对此修改没有要求',
    `phone_is_bind`    int(1) DEFAULT '2' COMMENT '手机是否绑定，1是，2否',
    `bank_card_type`   int(1) DEFAULT '0' COMMENT '账号类型,0法人，1代理人',
    `company_name`     varchar(120)                                                 DEFAULT '' COMMENT '公司名称',
    `certificate_type` varchar(10)                                                  DEFAULT '' COMMENT '公司证件类型(1-身份证；3-回乡证；4-中国护照；5-台胞证；19-外国护照；52-组织机构代码证；68-营业执照 ；73-统一社会信用代码)',
    `certificate_code` varchar(32)                                                  DEFAULT NULL COMMENT '公司证件号码',
    `store_id`         varchar(32)                                                  DEFAULT NULL COMMENT '店铺id',
    `store_name`       varchar(120)                                                 DEFAULT NULL COMMENT '店铺名称',
    `legal_code`       varchar(32)                                                  DEFAULT NULL COMMENT '法人证件号码',
    `legal_type`       varchar(32)                                                  DEFAULT NULL COMMENT '法人证件类型',
    `legal_name`       varchar(120)                                                 DEFAULT NULL COMMENT '法人名称',
    `business_flag`    varchar(120)                                                 DEFAULT NULL COMMENT '是否个体工商户,1：是 2：否',
    `creator`          varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
    `create_time`      datetime NOT NULL                                            DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`          varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者',
    `update_time`      datetime NOT NULL                                            DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`          bit(1)   NOT NULL                                            DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`        bigint(19) NOT NULL DEFAULT '0' COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE,
    KEY                `merchant_id` (`merchant_id`) USING BTREE
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8
  ROW_FORMAT = COMPACT COMMENT ='见证宝资金账户身份认证表';

/*Data for the table `pay_card` */

/*Table structure for table `pay_draw_cash` */

DROP TABLE IF EXISTS `pay_draw_cash`;

CREATE TABLE `pay_draw_cash`
(
    `id`          bigint(19) NOT NULL AUTO_INCREMENT COMMENT '维一标识',
    `merchant_id` bigint(19) NOT NULL COMMENT '商户编号',
    `draw_type`   int(1) DEFAULT '0' COMMENT '提款类型 ,0个人，1公司',
    `serial_no`   varchar(36)                                                  DEFAULT '' COMMENT '提款流水号',
    `pay_date`    datetime                                                     DEFAULT NULL COMMENT '打款时间',
    `amount`      decimal(20, 2)                                               DEFAULT NULL COMMENT '提款金额',
    `body`        varchar(2000)                                                DEFAULT '' COMMENT '提款描述',
    `status`      tinyint(1) DEFAULT '0' COMMENT '状态(1:提款成功,2:提款失败,3:提现中或者新建,4:取消提款,5:退单)',
    `hand_fee`    decimal(20, 2)                                               DEFAULT NULL COMMENT '提现手续费用',
    `draw_msg`    varchar(2000)                                                DEFAULT '' COMMENT '提现描述信息(记录提现异常消息)',
    `creator`     varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
    `create_time` datetime NOT NULL                                            DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间,申请提款时间',
    `updater`     varchar(64)                                                  DEFAULT NULL COMMENT '更新者',
    `update_time` datetime                                                     DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
    `tenant_id`   bigint(19) NOT NULL DEFAULT '0' COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE,
    KEY           `merchant_id` (`merchant_id`) USING BTREE
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8
  ROW_FORMAT = COMPACT COMMENT ='提款申请记录表';

/*Data for the table `pay_draw_cash` */

/*Data for the table `pay_draw_cash_company` */

/*Table structure for table `pay_fund` */

DROP TABLE IF EXISTS `pay_fund`;

CREATE TABLE `pay_fund`
(
    `id`            bigint(19) NOT NULL AUTO_INCREMENT COMMENT '标识Id',
    `merchant_id`   bigint(19) NOT NULL COMMENT '商户编号',
    `balance`       decimal(20, 2) DEFAULT NULL COMMENT '可用余额',
    `freeze`        decimal(20, 2) DEFAULT NULL COMMENT '冻结资金',
    `amount`        decimal(20, 2) DEFAULT NULL COMMENT '总额',
    `jzb_code`      varchar(32)    DEFAULT '' COMMENT '平安银行见证宝维一编码',
    `jzb_status`    tinyint(1) DEFAULT '0' COMMENT '见证宝同步状态0:未同步;1:同步',
    `v_member_id`   varchar(36)    DEFAULT '' COMMENT '虚拟会员ID，与平安鉴证宝一一对应',
    `amount_quota`  varchar(11)    DEFAULT '500' COMMENT '提现金额的可提现的额度',
    `interest_rate` decimal(4,2) DEFAULT '0.00' COMMENT '服务费利率',
    `set_up`            tinyint(2)                                                   DEFAULT '1' COMMENT '设置取默认或者手动设置费率 1:默认 2：手动',
    `contract_no`       varchar(50)                                                  DEFAULT '' COMMENT '会员电子协议编号',
    `rein_success_flag` varchar(10)                                                  DEFAULT '' COMMENT '见证宝签约否成功标志S-成功 F-失败',
    `ip_address`        varchar(100)                                                 DEFAULT '' COMMENT '见证宝签约IP地址',
    `mac_address`       varchar(100)                                                 DEFAULT '' COMMENT '见证宝签约MAC地址',
    `sign_channel`      varchar(100)                                                 DEFAULT '' COMMENT '见证宝签约渠道1-app 2-平台H5网页 3-公众号 4-小程序    功能标志FunctionFlag=1时必输',
    `creator`           varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
    `create_time`       datetime   NOT NULL                                          DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`           varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者',
    `update_time`       datetime   NOT NULL                                          DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`           bit(1)     NOT NULL                                          DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`         bigint(19) NOT NULL                                          DEFAULT '0' COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE KEY `merchant_id` (`merchant_id`) USING BTREE
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8
  ROW_FORMAT = COMPACT COMMENT ='用户资金表';

/*Data for the table `pay_fund` */

/*Table structure for table `pay_fund_details` */

DROP TABLE IF EXISTS `pay_fund_details`;

CREATE TABLE `pay_fund_details`
(
    `id`            bigint(19) NOT NULL AUTO_INCREMENT COMMENT '标识Id',
    `merchant_id`   bigint(19) NOT NULL COMMENT '商户编号',
    `balance`       decimal(20, 2)                                               DEFAULT NULL COMMENT '可用余额',
    `profit`        decimal(20, 2)                                               DEFAULT NULL COMMENT '盈利金额',
    `draw_profit`   decimal(20, 2)                                               DEFAULT NULL COMMENT '提款金额',
    `freeze_profit` decimal(20, 2)                                               DEFAULT NULL COMMENT '冻结货款金额',
    `freeze`        decimal(20, 2)                                               DEFAULT NULL COMMENT '冻结金额',
    `amount`        decimal(20, 2)                                               DEFAULT NULL COMMENT '总额',
    `trade_amount`  decimal(20, 2)                                               DEFAULT NULL COMMENT '交易金额',
    `order_id`      bigint(19) NOT NULL COMMENT '支付订单Id',
    `body`          varchar(500)                                                 DEFAULT '' COMMENT '交易描述',
    `trade_type`    tinyint(1) DEFAULT '0' COMMENT '交易类型,0:默认,1:收入,2:支出,3:状态变化',
    `creator`       varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
    `create_time`   datetime NOT NULL                                            DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`       varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者',
    `update_time`   datetime NOT NULL                                            DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`       bit(1)   NOT NULL                                            DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`     bigint(19) NOT NULL DEFAULT '0' COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE,
    KEY             `order_id` (`order_id`) USING BTREE
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8
  ROW_FORMAT = COMPACT COMMENT ='用户资金收支明细表';

/*Data for the table `pay_fund_details` */

/*Table structure for table `pay_jzb_order` */

DROP TABLE IF EXISTS `pay_jzb_order`;

CREATE TABLE `pay_jzb_order`
(
    `id`                bigint(19) NOT NULL AUTO_INCREMENT COMMENT '标识Id(订单Id)',
    `trade_date`        datetime          DEFAULT NULL COMMENT '交易日期',
    `merchant_id`       varchar(36)       DEFAULT '' COMMENT '商户ID(卖家(商家)ID)',
    `amount`            decimal(20, 2)    DEFAULT NULL COMMENT '订单金额',
    `pay_order_id`      bigint(19) NOT NULL COMMENT '支付订单ID',
    `trade_status`      tinyint(1) DEFAULT '0' COMMENT '支付订单状态,0:等待付款,1:交易成功,2:付款失败,3:取消订单,4:退款申请中,5:退款成功,6:订单过期',
    `trade_type`        tinyint(4) DEFAULT '0' COMMENT '交易类型,0:其他,1:支付,2:充值,3:提现,4:转账,5:消费',
    `third_id`          varchar(64)       DEFAULT '' COMMENT '第三方返回订单流水号',
    `jzb_freeze_status` tinyint(1) DEFAULT '0' COMMENT '见证宝冻结状态，是否冻结(0:待冻结，1:冻结，2:解冻)',
    `jzb_status`        tinyint(1) DEFAULT '0' COMMENT '支付成功订单同步到平安银行状态(0:未同步见证宝,1:已同步见证宝)',
    `jzb_front_log_no`  varchar(150)      DEFAULT NULL COMMENT '见证宝返回前置流水号',
    `remarks`           varchar(200)      DEFAULT '' COMMENT '备注',
    `create_time`       datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间(订单生成时间)',
    `update_time`       datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`           bit(1)   NOT NULL DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`         bigint(19) NOT NULL DEFAULT '0' COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE,
    KEY                 `merchant_id` (`merchant_id`) USING BTREE,
    KEY                 `order_id` (`pay_order_id`) USING BTREE
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8
  ROW_FORMAT = COMPACT COMMENT ='见证宝订单表(挂账)';

/*Data for the table `pay_jzb_order` */

/*Table structure for table `pay_jzb_refund` */

DROP TABLE IF EXISTS `pay_jzb_refund`;

CREATE TABLE `pay_jzb_refund`
(
    `id`            bigint(19) NOT NULL AUTO_INCREMENT COMMENT '退款单号',
    `merchant_id`   bigint(19) NOT NULL COMMENT '商户编号',
    `order_id`      bigint(19) NOT NULL COMMENT '交易单号',
    `third_id`      varchar(36)                                                  DEFAULT '' COMMENT '第三方平台流水号',
    `third_fund_id` varchar(36)                                                  DEFAULT '' COMMENT '第三方平台退款单号',
    `total_amount`  decimal(20, 2)                                               DEFAULT NULL COMMENT '订单金额',
    `refund_amount` decimal(20, 2)                                               DEFAULT NULL COMMENT '退款金额',
    `refund_status` tinyint(1) DEFAULT NULL COMMENT '退款状态(1:退款成功,2:退款失败,3:新建)',
    `creator`       varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
    `create_time`   datetime NOT NULL                                            DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`       varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者',
    `update_time`   datetime NOT NULL                                            DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`       bit(1)   NOT NULL                                            DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`     bigint(19) NOT NULL DEFAULT '0' COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE,
    KEY             `order_id` (`order_id`) USING BTREE
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8
  ROW_FORMAT = COMPACT COMMENT ='见证宝退款记录表(销账)';

/*Data for the table `pay_jzb_refund` */


--- 20240115 退款
/*Table structure for table `pay_jzb_sub_order`
 * 见证宝子订单信息，用于冻结充值撤销和分账撤销
*/
DROP TABLE IF EXISTS `pay_jzb_sub_order`;
CREATE TABLE `pay_jzb_sub_order`
(
    `id`                     bigint(19) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `merchant_id`            bigint(19) NOT NULL COMMENT '商户编号',
    `jzb_order_id`           bigint(19) NOT NULL COMMENT '见证宝订单号',
    `order_status`           tinyint(2) DEFAULT 0 COMMENT '见证宝订单状态, 0冻结中 1冻结成功 2冻结失败 4冻结撤销中 5冻结撤销成功 6冻结撤销失败 7分账中 8分账成功 9分账失败 10分账撤销中 11分账撤销成功 12分账撤销失败',
    `recharge_seq_no`        varchar(30)                                                  DEFAULT '' COMMENT '冻结充值交易流水号,用于KFEJZB6273查询交易终态',
    `recharge_orders`        varchar(300)                                                 DEFAULT '' COMMENT '冻结充值子订单信息',
    `recharge_cancel_seq_no` varchar(30)                                                  DEFAULT '' COMMENT '冻结充值撤销交易流水号',
    `recharge_cancel_orders` varchar(300)                                                 DEFAULT '' COMMENT '冻结充值撤销子订单信息',
    `recharge_total_amount`  decimal(20, 2)                                               DEFAULT NULL COMMENT '冻结充值撤销总金额',
    `sub_acct_seq_no`        varchar(30)                                                  DEFAULT '' COMMENT '分账交易流水号',
    `sub_acct_orders`        varchar(300)                                                 DEFAULT '' COMMENT '分账子订单信息',
    `sub_acct_cancel_seq_no` varchar(30)                                                  DEFAULT '' COMMENT '分账撤销交易流水号',
    `sub_acct_cancel_orders` varchar(300)                                                 DEFAULT '' COMMENT '分账撤销子订单信息',
    `sub_acct_total_amount`  decimal(20, 2)                                               DEFAULT NULL COMMENT '分账撤销总金额',
    `creator`                varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
    `create_time`            datetime NOT NULL                                            DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updater`                varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者',
    `update_time`            datetime NOT NULL                                            DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted`                bit(1)   NOT NULL                                            DEFAULT b'0' COMMENT '是否删除',
    `tenant_id`              bigint(19) NOT NULL DEFAULT '0' COMMENT '租户编号',
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE KEY `uni_jzb_order_id` (`jzb_order_id`) USING BTREE
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8
  ROW_FORMAT = COMPACT COMMENT ='见证宝子订单信息';

/*Data for the table `pay_jzb_sub_order` */

-- -----------------------------------------
-- --------------见证宝相关end--------------
-- -----------------------------------------

/*Table structure for table `undo_log` */
DROP TABLE IF EXISTS `undo_log`;
CREATE TABLE `undo_log`
(
    `id`            bigint                                                        NOT NULL AUTO_INCREMENT,
    `branch_id`     bigint                                                        NOT NULL,
    `xid`           varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
    `context`       varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
    `rollback_info` longblob                                                      NOT NULL,
    `log_status`    int                                                           NOT NULL,
    `log_created`   datetime                                                      NOT NULL,
    `log_modified`  datetime                                                      NOT NULL,
    PRIMARY KEY (`id`) USING BTREE,
    UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`) USING BTREE
) ENGINE = InnoDB
  AUTO_INCREMENT = 74
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci;


